using System.IO;
using System.Text;
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
using System;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;

public class ModelCreateScript : EndNameEditAction
{
    public static string objName { set; get; }

    public override void Action(int instanceId, string pathName, string resourceFile)
    {
        string text = File.ReadAllText(resourceFile);
        string className = Path.GetFileNameWithoutExtension(pathName);
        string tab = "   ";
        className = className.Replace(" ", "");

        text = "using FutureCore;\n\n";
        text += "public class " + className + " : BaseModel\n{\n" + tab + "";
        text += "#region BaseModel\n" + tab + "";
        text += "protected override void OnInit()\n" + tab + "{\n" + tab + "}\n\n" + tab + "";
        text += "protected override void OnDispose()\n" + tab + "{\n" + tab + "}\n\n" + tab + "";
        text += "protected override void OnReset()\n" + tab + "{\n" + tab + "}\n" + tab + "";
        text += "#endregion";
        text += "\n}\n";

        UTF8Encoding encoding = new UTF8Encoding(true, false);

        File.WriteAllText(pathName, text, encoding);

        AssetDatabase.ImportAsset(pathName);
        MonoScript asset = AssetDatabase.LoadAssetAtPath<MonoScript>(pathName);
        ProjectWindowUtil.ShowCreatedAsset(asset);
    }
}